﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;

namespace Ewts.RDLC
{
    public partial class OutStorage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);       //清理缓存，保证刷新页面数据是最新的
            if (!Page.IsPostBack)
            {
                int outStorID = 0;
                if (Request["outStorID"] != null && Request["outStorID"].ToString().Trim() != "")
                {
                    outStorID = int.Parse(Request["outStorID"].ToString().Trim());
                }

                BindData(outStorID);
            }
        }

        protected void BindData(int outStorID)
        {
            List<ReportParameter> parameterList = new List<ReportParameter>();
            DataSet barCodeDS = new DataLib.BLL.BarCode().GetBarList("outstrorageid = '" + outStorID + "'");
            DataLib.Model.OutStorage outModel = new DataLib.BLL.OutStorage().GetModel(outStorID);

            //参数数据
            if(outModel != null)
            {
                parameterList.Add(new ReportParameter("Date", ((DateTime)outModel.outStorageDate).ToLongDateString().ToString()));
                parameterList.Add(new ReportParameter("No", outModel.outStorageNo));
                parameterList.Add(new ReportParameter("ConsumMan", outModel.ConsumMan));
                parameterList.Add(new ReportParameter("DoCustomer", outModel.DoCustomer));
                parameterList.Add(new ReportParameter("ConsumMan", outModel.OutsNo));

                string paramOutType = "默认值";
                switch(outModel.outStorageType)
                {
                    case "1":
                        paramOutType = "出库拆解";
                        break;
                    case "2":
                         paramOutType = "出库分类";
                        break;
                    case "3":
                         paramOutType = "领料生产";
                        break;
                    case "4":
                         paramOutType = "出库销售";
                        break;
                    case "5":
                         paramOutType = "移库出库";
                        break;
                    case "31":
                        paramOutType = "生产出库";
                        break;
                    default:
                        break;
                }
                parameterList.Add(new ReportParameter("OutStorType",paramOutType));

                
            }

            //为列表绑定数据
            ReportDataSource rds = new ReportDataSource("DataSet1", barCodeDS.Tables[0]);
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.LocalReport.DataSources.Add(rds);
            new RDLCPrinter().FillRow(barCodeDS.Tables[0], 3,25,25);//为列表添加空行
            ReportViewer1.LocalReport.SetParameters(parameterList);
            ReportViewer1.LocalReport.Refresh();
        }
    }
}